package com.zzyl.controller;

import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserAddDto;
import com.zzyl.dto.UserDto;
import com.zzyl.dto.UserPageDto;
import com.zzyl.dto.UserUpdateDto;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user")
@RestController
@Api("用户管理")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation("用户分页")
    public ResponseResult userPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize ,@RequestBody UserPageDto userPageDto){
        PageResponse<UserPageVo> userPageVos = userService.userPage(pageNum,pageSize,userPageDto);
        return ResponseResult.success(userPageVos);
    }

    @PutMapping
    @ApiOperation("用户添加")
    public ResponseResult addUser(@RequestBody UserAddDto dto){
        userService.addUser(dto);
        return ResponseResult.success();
    }

    @PostMapping("/reset-passwords/{userId}")
    @ApiOperation("重置密码")
    public ResponseResult updateUserPassword(@PathVariable Long userId){
        userService.updateUserPassword(userId);
        return ResponseResult.success();
    }

    @PutMapping("/is-enable/{id}/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult updateUserStatus(@PathVariable Long id,@PathVariable Integer status){
        userService.updateUserStatus(id,status);
        return ResponseResult.success();
    }

    @DeleteMapping("/remove/{userIds}")
    @ApiOperation("删除用户")
    public ResponseResult removeUser(@PathVariable Long userIds){
        userService.removeUser(userIds);
        return ResponseResult.success();
    }

    @PatchMapping
    @ApiOperation("用户修改")
    public ResponseResult updateUser(@RequestBody  UserUpdateDto dto){
        userService.updateUser(dto);
        return ResponseResult.success();
    }

}
